using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using System;
using System.Data;
namespace AppToolKit.Data.NHibernate
{
	public class TrimmedString : IUserType
	{
		public SqlType[] SqlTypes
		{
			get
			{
				return new SqlType[]
				{
					new SqlType(DbType.String)
				};
			}
		}
		public Type ReturnedType
		{
			get
			{
				return typeof(string);
			}
		}
		public bool IsMutable
		{
			get
			{
				return false;
			}
		}
		public object NullSafeGet(IDataReader rs, string[] names, object owner)
		{
			string text = (string)NHibernateUtil.String.NullSafeGet(rs, names[0]);
			object result;
			if (text != null)
			{
				result = text.Trim();
			}
			else
			{
				result = null;
			}
			return result;
		}
		public void NullSafeSet(IDbCommand cmd, object value, int index)
		{
			if (value == null)
			{
				NHibernateUtil.String.NullSafeSet(cmd, null, index);
			}
			else
			{
				value = ((string)value).Trim();
				NHibernateUtil.String.NullSafeSet(cmd, value, index);
			}
		}
		public object DeepCopy(object value)
		{
			object result;
			if (value == null)
			{
				result = null;
			}
			else
			{
				result = string.Copy((string)value);
			}
			return result;
		}
		public object Replace(object original, object target, object owner)
		{
			return original;
		}
		public object Assemble(object cached, object owner)
		{
			return this.DeepCopy(cached);
		}
		public object Disassemble(object value)
		{
			return this.DeepCopy(value);
		}
		public new bool Equals(object x, object y)
		{
			return x != null && y != null && x.Equals(y);
		}
		public int GetHashCode(object x)
		{
			return x.GetHashCode();
		}
	}
}
